
\section{The xtplfc command}
{\tt xtplfc} estimates \citeauthor{yonghong2016semiparametric}'s \citeyearpar{yonghong2016semiparametric} partially linear functional-coefficient panel data models with exogenous variables.

\subsection{Syntax}
\begin{stsyntax}
	xtplfc\
	\varlist,\
	\underbar{z}vars(\varlist)
	\underbar{u}vars(\varlist)
	\underbar{gen}erate(\ststring)
	\optional{
		    power(\textit{numlist})
		    \underbar{nk}nots(\textit{numlist})
		    \underbar{quan}tile
		    \underbar{maxnk}nots(\textit{numlist})
		    \underbar{minnk}nots(\textit{numlist})
		    grid(\ststring)
		    pctile(\num)
		    brep(\num)
		    wild
		    predict(\textit{prspec})
		    nodots
		    level(\num)
		    fast
		    tenfoldcv
 }
\end{stsyntax}


\subsection{Options}

\hangpara
{\tt zvars(\varlist)} specifies variables that have functional coefficients. It is required.

\hangpara
{\tt uvars(\varlist)} specifies (continuous) variables that enter the functional coefficients interacted with variables
specified by zvars() in order. It is required.

\hangpara
{\tt generate(\ststring)} specifies a prefix for the names to store fitted values of functional coefficients. It is required.

\hangpara
{\tt te} specifies including time fixed effects.

\hangpara
{\tt power(\textit{numlist})} specifies the power (or degree) of the splines; default is power(3).

\hangpara
{\tt nknots(\textit{numlist})} specifies the number of knots used for the spline interpolation in order specified by uvars().  If
absent, 2 is assumed for all the functions.

\hangpara
{\tt quantile} specifies creating knots based on empirical quantiles. By default, the knots are generated by the rule of
equal space.

\hangpara
{\tt maxnknots(\textit{numlist})} specifies the maximum number of knots used for conducting least-squares cross-validation(LSCV). If present, LSCV is employed to
determine the optimal number of knots. In our practice, we perform the Leave-One-Out cross-validation (CV) across the panelvar. That
is to say, we leave one individual (with all observations during the sample period) out each time.


\hangpara
{\tt minnknots(\textit{numlist})} specifies the minimun number of knots used for performing LSCV. If absent, 2 is assumed.

\hangpara
{\tt grid(\ststring)} specifies a prefix for the names to store the grid points of the variable specified by uvars(\varlist).

\hangpara
{\tt pctile(\num)} specifies the domain of the generating grid points; default is pctile(0).

\hangpara
{\tt brep(\num)} specifies the number of bootstrap replications. The default is bootstrap(200).

\hangpara
{\tt wild} specifies using the wild bootstrap. By default, residual bootstrap with cluster(panelvar) is performed.

\hangpara
{\tt predict(\textit{prspec})} stores predicted values of the conditional mean and fixed effects using variable names specified in \textit{prspec}. Specifically, the expression is predict(\varlist $|$ \textit{stub}* [, \textit{replace noai}]). The option takes a variable list or a stub.  The first variable name corresponds to the predicted conditional mean. The second name corresponds to fixed effects.When \textit{replace} is used, variables with the names in \textit{varlist} or \textit{stub}* are replaced by those in the new computation. If \textit{noai} is specified, only a variable for the mean is created.

\hangpara
{\tt nodots} suppresses iteration dots.

\hangpara
{\tt level(\num)} sets confidence level; default is level(95).

\hangpara
{\tt fast} speeds up using mata functions.

\hangpara
{\tt tenfoldcv} specifies using ten-fold CV. It is done by dividing the sample into ten pieces and conduct LSCV across these ten pieces. Specifically, given the
number of knots, leave one piece out, run the regression using the left pieces and predict the dependent variable for the leaving piece.



\subsection{Stored results}


{\tt xtplfc} stores the following in {\tt e()}:\\


\begin{stresults}
	\stresultsgroup{Scalars} \\
	\stcmd{e(N)} & number of individuals
	\\
	\stcmd{e(df\_m)} & model degrees of freedom
	\\
	\stcmd{e(df\_r)} & residual degrees of freedom
	\\
	\stcmd{e(r2)} & within R-squared	
	\\
	\stcmd{e(r2\_a)} & adjusted within R-squared	
	\\
	\stcmd{e(rmse)} & root mean squared error	
	\\
	\stcmd{e(mss)} & model sum of squares
	\\
	\stcmd{e(rss)} & residual sum of squares	
    \\	
	\stresultsgroup{Matrix} \\	
	\stcmd{e(b)} & coefficient vector in the linear part
    \\	
    \stcmd{e(V)} & variance-covariance matrix of the estimators in the linear part
    \\	
    \stcmd{e(bs)} & coefficient vector in the approximating model
    \\	
    \stcmd{e(Vs)} & variance-covariance matrix of the estimators in the approximating model
    \\	
    \stcmd{e(knots)} & number of knots
    \\
    \stcmd{e(power)} & number of power (or degree) of splines
    \\
	\stresultsgroup{Macros} \\
	\stcmd{e(cmd)} & xtplfc
	\\
	\stcmd{e(depvar)} & name of dependent variable
	\\
	\stcmd{e(title)} & title in estimation output
	\\
	\stcmd{e(estfun)} & variables storing the estimated functional coefficients
    \\
    \stcmd{e(vcetype)} & type of variance-covariance
    \\
    \stcmd{e(model)} & Fixed-effect Series Semiparametric Estimation
    \\
	\stcmd{e(k\#)} & list of knots for the \#th function
	\\    	


\end{stresults}


\subsection{Dependency of xtplfc}
{\tt xtplfc} depends on the moremata and bspline packages.

\section{The ivxtplfc command}
{\tt ivxtplfc} estimates \citeauthor{Zhang2018}'s \citeyearpar{Zhang2018} partially linear functional-coefficient panel data models with endogenous variables using the sieve 2SLS method.

\subsection{Syntax}
\begin{stsyntax}
	ivxtplfc\
	\varlist,\
	\underbar{u}vars(\varlist)
	\underbar{gen}erate(\ststring)
	\optional{
		\underbar{z}vars(\varlist)
		endox(\varlist)
		\underbar{endoz}flag(\textit{numlist})
		ivx(\varlist)
		ivz(\varlist, uflag(\textit{numlist}) [ivtype(\num)])		
		power(\textit{numlist})
		\underbar{nk}nots(\textit{numlist})
		\underbar{quan}tile(\textit{numlist})
		\underbar{maxnk}nots(\textit{numlist})
		\underbar{maxnk}nots(\textit{numlist})
		grid(\ststring)
		pctile(\num)
		brep(\num)
		wild
		predict(\textit{prspec})
		nodots
		level(\num)
		fast
		tenfoldcv
	}
\end{stsyntax}


\subsection{Options}

\hangpara
{\tt uvars(\varlist)} specifies (continuous) variables that enter the functional coefficients interacted with variables
specified by zvars() in order. It is required.

\hangpara
{\tt generate(\ststring)} specifies a prefix for the names to store fitted values of functional coefficients. It is required.

\hangpara
{\tt zvars(\varlist)} specifies variables that have functional coefficients.

\hangpara
{\tt endox(\varlist)} specifies endogeneous variables which enter the model linearly.

\hangpara
{\tt endozflag(\textit{numlist})} specify the orders of variables in zvars(\varlist) which are endogeneous variables. For example,
endozflag(1 3) indicates that the first and third variables specified in zvars(\varlist) are endogeneous.


\hangpara
{\tt ivx(\varlist)} specifies instrumental variables which enter the model linearly.

\hangpara
{\tt ivz(\varlist, uflag(\textit{numlist}) [ivtype\textit{(numlist})])} specify instrumental variables entering the model nonlinearly which
interacts with the functions specified by the orders in uflag(numlist). Optionally, one may specify the type of
nonlinear instrumental variables to be constructed. ivtype(\#) means using the \#th lag of the basis functions and the
final IVs are formed from "ivz$\times$L\#.S(u)" (where S(u) are basis functions of u). By default, the first lag of the basis functions are used.


\hangpara
{\tt te} specifies including time fixed effects.

\hangpara
{\tt power(\textit{numlist})} specifies the power (or degree) of the splines; default is power(3).

\hangpara
{\tt nknots(\textit{numlist})} specifies the number of knots used for the spline interpolation in order specified by uvars().  If
absent, 2 is assumed for all the functions.

\hangpara
{\tt quantile} specifies creating knots based on empirical quantiles. By default, the knots are generated by the rule of
equal space.

\hangpara
{\tt maxnknots(\textit{numlist})} specifies the maximun number of knots used for conducting least-squares cross-validation (LSCV). If present, LSCV is employed to
determine the optimal number of knots. In our practice, we perform the Leave-One-Out CV across the panelvar. That
is to say, we leave one individual (with all observations during the sample period) out each time.


\hangpara
{\tt minnknots(\textit{numlist})} specifies the minimun number of knots used for performing LSCV. If absent, 2 is assumed.

\hangpara
{\tt grid(\ststring)} specifies a prefix for the names to store the grid points of the variable specified by uvars(\varlist).

\hangpara
{\tt pctile(\num)} specifies the domain of the generating grid points; default is pctile(0).

\hangpara
{\tt brep(\num)} specifies the number of bootstrap replications. The default is bootstrap(200).

\hangpara
{\tt wild} specifies using the wild bootstrap. By default, residual bootstrap with cluster(panelvar) is performed.

\hangpara
{\tt predict(\textit{prspec})} stores predicted values of the conditional mean and fixed effects using variable names specified in \textit{prspec}. Specifically, the expression is predict(\varlist $|$ \textit{stub}* [, \textit{replace noai}]). The option takes a variable list or a stub.  The first variable name corresponds to the predicted conditional mean. The second name corresponds to fixed effects.When \textit{replace} is used, variables with the names in \textit{varlist} or \textit{stub}* are replaced by those in the new computation. If \textit{noai} is specified, only a variable for the mean is created.

\hangpara
{\tt nodots} suppresses iteration dots.

\hangpara
{\tt level(\num)} sets confidence level; default is level(95).

\hangpara
{\tt fast} speeds up using mata functions.

\hangpara
{\tt tenfoldcv} specifies using ten-fold CV.

\subsection{Stored results}


{\tt ivxtplfc} stores the following in {\tt e()}:\\


\begin{stresults}
	\stresultsgroup{Scalars} \\
	\stcmd{e(N)} & number of individuals
	\\
	\stcmd{e(df\_m)} & model degrees of freedom
	\\
	\stcmd{e(df\_r)} & residual degrees of freedom
	\\
	\stcmd{e(r2)} & within R-squared	
	\\
	\stcmd{e(r2\_a)} & adjusted within R-squared	
	\\
	\stcmd{e(rmse)} & root mean squared error	
	\\
	\stcmd{e(mss)} & model sum of squares
	\\
	\stcmd{e(rss)} & residual sum of squares	
	\\	
	\stresultsgroup{Matrix} \\	
	\stcmd{e(b)} & coefficient vector in the linear part
	\\	
	\stcmd{e(V)} & variance-covariance matrix of the estimators in the linear part
	\\	
	\stcmd{e(bs)} & coefficient vector in the approximating model
	\\	
	\stcmd{e(Vs)} & variance-covariance matrix of the estimators in the approximating model
	\\	
	\stcmd{e(knots)} & number of knots
	\\
	\stcmd{e(power)} & number of power (or degree) of splines
	\\
	\stresultsgroup{Macros} \\
	\stcmd{e(cmd)} & ivxtplfc
	\\
	\stcmd{e(depvar)} & name of dependent variable
	\\
	\stcmd{e(title)} & title in estimation output
	\\
	\stcmd{e(estfun)} & variables storing the estimated functional coefficients
	\\
	\stcmd{e(vcetype)} & type of variance-covariance
	\\
	\stcmd{e(model)} & Fixed-effect Series Semiparametric Estimation
	\\
	\stcmd{e(k\#)} & list of knots for the \#th function
	\\
	\stcmd{e(ivlist)} & instrumental variables used for estimation.
	\\    		   	
	
\end{stresults}


\subsection{Dependency of ivxtplfc}
{\tt ivxtplfc} depends on the moremata and bspline packages.

\section{The xtdplfc command}
{\tt xtdplfc} estimates  \citeauthor{Zhang2018}'s \citeyearpar{Zhang2018} partially linear functional-coefficient panel dynamic data models using the sieve 2SLS method.

\subsection{Syntax}
\begin{stsyntax}
	xtdplfc\
	\varlist,\
	\underbar{u}vars(\varlist)
	\underbar{gen}erate(\ststring)
	\optional{
		\underbar{z}vars(\varlist)
		lag(\num)
		lagyinz(\textit{numlist})
		endox(\varlist)
		\underbar{endoz}flag(\textit{numlist})
		ivx(\varlist)
		ivz(\varlist, uflag(\textit{numlist}) [ivtype(\num)])
		\underbar{only}ivxz
        ivtype(\textit{numlist})					
		power(\textit{numlist})
		\underbar{nk}nots(\textit{numlist})
		\underbar{quan}tile(\textit{numlist})
		\underbar{maxnk}nots(\textit{numlist})
		grid(\ststring)
		pctile(\num)
		brep(\num)
		wild
		predict(\textit{prspec})
		nodots
		level(\num)
		fast
		tenfoldcv
	}
\end{stsyntax}


\subsection{Options}

\hangpara
{\tt uvars(\varlist)} specifies (continuous) variables that enter the functional coefficients interacted with variables
specified by zvars() in order. It is required.

\hangpara
{\tt generate(\ststring)} specifies a prefix for the names to store fitted values of functional coefficients. It is required.

\hangpara
{\tt zvars(\varlist)} specifies variables that have functional coefficients.

\hangpara
{\tt lag(\num)} specifies using \num  lags of dependent variable as covariates; default is lags(1).

\hangpara
{\tt lagyinz(\textit{numlist})} speficies lags of dependent variable that have functional coefficients. When this option is used, the
specified lags of depvar are automatically added in the front of variables in zvars(\varlist).

\hangpara
{\tt endox(\varlist)} specifies endogeneous variables which enter the model linearly.

\hangpara
{\tt endozflag(\textit{numlist})} specify the orders of variables in zvars(\varlist) which are endogeneous variables. For example,
endozflag(1 3) indicates that the first and third variables specified in zvars(\varlist) are endogeneous.


\hangpara
{\tt ivx(\varlist)} specifies instrumental variables which enter the model linearly.

\hangpara
{\tt ivz(\varlist, uflag(\textit{numlist}) [ivtype\textit{(numlist})])} specify instrumental variables entering the model nonlinearly which
interacts with the functions specified by the orders in uflag(numlist).  Optionally, one may specify the type of
nonlinear instrumental variables to be constructed. ivtype(\#) means using the \#th lag of the basis functions and the
final IVs are formed from "ivz$\times$L\#.S(u)" (where S(u) are basis functions of u). By default, the first lag of the basis functions are used.

\hangpara
{\tt onlyivxz} only uses instruments specified by ivx() and ivz(). By default, addtional instruments are
automatically constructed using lags of dependent variables, variables specified by endox() and endozflag(), and
the generating splines.


\hangpara
{\tt ivtype(\textit{numlist})}  speficies the lag of the basis functions to be used for constructing the IVs.  Suppose Z is an
endogeneous variable interacting with g(U); S(U) are basis functions for g(U). ivtype(1) indicates constructing IVs
from "L2.Z$\times$L.S(U)".

\hangpara
{\tt te} specifies including time fixed effects.


\hangpara
{\tt power(\textit{numlist})} specifies the power (or degree) of the splines; default is power(3).

\hangpara
{\tt nknots(\textit{numlist})} specifies the number of knots used for the spline interpolation in order specified by uvars().  If
absent, 2 is assumed for all the functions.

\hangpara
{\tt quantile} specifies creating knots based on empirical quantiles. By default, the knots are generated by the rule of
equal space.

\hangpara
{\tt maxnknots(\textit{numlist})} specifies the maximun number of knots used for conducting least-squares cross-validation (LSCV). If present, LSCV is employed to
determine the optimal number of knots. In our practice, we perform the Leave-One-Out CV across the panelvar. That
is to say, we leave one individual (with all observations during the sample period) out each time.


\hangpara
{\tt minnknots(\textit{numlist})} specifies the minimun number of knots used for performing LSCV. If absent, 2 is assumed.

\hangpara
{\tt grid(\ststring)} specifies a prefix for the names to store the grid points of the variable specified by uvars(\varlist).

\hangpara
{\tt pctile(\num)} specifies the domain of the generating grid points; default is pctile(0).

\hangpara
{\tt brep(\num)} specifies the number of bootstrap replications. The default is bootstrap(0).

\hangpara
{\tt wild} specifies using the wild bootstrap. By default, residual bootstrap with cluster(panelvar) is performed.

\hangpara
{\tt predict(\textit{prspec})} stores predicted values of the conditional mean and fixed effects using variable names specified in \textit{prspec}. Specifically, the expression is predict(\varlist $|$ \textit{stub}* [, \textit{replace noai}]). The option takes a variable list or a stub.  The first variable name corresponds to the predicted conditional mean. The second name corresponds to fixed effects.When \textit{replace} is used, variables with the names in \textit{varlist} or \textit{stub}* are replaced by those in the new computation. If \textit{noai} is specified, only a variable for the mean is created.

\hangpara
{\tt nodots} suppresses iteration dots.

\hangpara
{\tt level(\num)} sets confidence level; default is level(95).

\hangpara
{\tt fast} speeds up using mata functions.

\hangpara
{\tt tenfoldcv} specifies using ten-fold CV.


\subsection{Stored results}


{\tt xtdplfc} stores the following in {\tt e()}:\\


\begin{stresults}
	\stresultsgroup{Scalars} \\
	\stcmd{e(N)} & number of individuals
	\\
	\stcmd{e(df\_m)} & model degrees of freedom
	\\
	\stcmd{e(df\_r)} & residual degrees of freedom
	\\
	\stcmd{e(r2)} & within R-squared	
	\\
	\stcmd{e(r2\_a)} & adjusted within R-squared	
	\\
	\stcmd{e(rmse)} & root mean squared error	
	\\
	\stcmd{e(mss)} & model sum of squares
	\\
	\stcmd{e(rss)} & residual sum of squares	
	\\	
	\stresultsgroup{Matrix} \\	
	\stcmd{e(b)} & coefficient vector in the linear part
	\\	
	\stcmd{e(V)} & variance-covariance matrix of the estimators in the linear part
	\\	
	\stcmd{e(bs)} & coefficient vector in the approximating model
	\\	
	\stcmd{e(Vs)} & variance-covariance matrix of the estimators in the approximating model
	\\	
	\stcmd{e(knots)} & number of knots
	\\
	\stcmd{e(power)} & number of power (or degree) of splines
	\\
	\stresultsgroup{Macros} \\
	\stcmd{e(cmd)} & xtdplfc
	\\
	\stcmd{e(depvar)} & name of dependent variable
	\\
	\stcmd{e(title)} & title in estimation output
	\\
	\stcmd{e(estfun)} & variables storing the estimated functional coefficients
	\\
	\stcmd{e(vcetype)} & type of variance-covariance
	\\
	\stcmd{e(model)} & Fixed-effect Series Semiparametric Estimation
	\\
	\stcmd{e(k\#)} & list of knots for the \#th function
	\\
	\stcmd{e(ivlist)} & instrumental variables used for estimation.
	\\    		   	
	
\end{stresults}


\subsection{Dependency of xtdplfc}
{\tt xtdplfc} depends on the moremata and bspline packages.



\section{Monte Carlo simulation}
\input{simulation.tex}

%\section{Example}

%\begin{stlog}
%	\input{example.log.tex}
%\end{stlog}

\section{Conclusion}
Partial linear functional-coefficient models are flexible enough to accommodate the nonlinear structure and capture the heterogeneity over individuals and times which have been popularly in academic research. This article briefly introduces the newly development of functional-coefficient panel data models, and provides three new Stata commands for implementing estimation. Additionally, we illustrate the usefulness of our proposed commands via some simple simulations.


\section{Acknowledgments}
  Kerui Du acknowledges financial support from the National Natural Science Foundation of China (No. 71603148). Qiankun Zhou acknowledges financial support from the National Natural Science Foundation of China (No. 71431006). We are grateful to the anonymous reviewer for the helpful comments and suggestions which led to an improved version of this paper. 

\endinput 